const connection = require("../app/database");

class FileService {
  async create(filename, mimetype, size, userId) {
    const statement =
      "insert into avatar (filename, mimetype, size, user_id) values (?, ?, ?, ?);";

    try {
      const [result] = await connection.execute(statement, [
        filename,
        mimetype,
        size,
        userId,
      ]);
      return result;
    } catch (e) {
      console.log(e);
    }
  }

  async queryAvatarWithUserId(userId) {
    const statement = "select * from avatar where user_id = ?;";
    const [result] = await connection.execute(statement, [userId]);
    return result.pop();
  }
}

module.exports = new FileService();
